package definite.Guide.Book.LayoutManager;

import java.awt.Component;
import java.awt.EventQueue;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.TitledBorder;

public class GlueSample {

	public static void main(String[] args) {
		Runnable r = new Runnable() {

			@Override
			public void run() {
				JFrame.setDefaultLookAndFeelDecorated(true);
				JFrame frame = new JFrame("Create Glue");
				frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
				frame.setLayout(new BoxLayout(frame.getContentPane(),
						BoxLayout.Y_AXIS));

				JPanel one = new JPanel();
				one.setBorder(new TitledBorder("First Panel"));
				JPanel tow = new JPanel();
				JPanel three = new JPanel();
				JPanel four = new JPanel();

				Component glue = Box.createHorizontalGlue();
				one.add(glue);
				for (int i = 1; i <= 4; i++) {
					JButton btn = new JButton("Button " + i);
					one.add(btn);
				}

				frame.add(one);
				frame.add(tow);
				frame.add(three);
				frame.add(four);
				frame.setLocationRelativeTo(null);
				frame.setSize(400, 300);
				frame.setResizable(false);
				frame.setVisible(true);
			}
		};

		EventQueue.invokeLater(r);
	}
}
